<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="数据日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dataDt">
              <j-date placeholder="请输入数据日期" v-model="model.dataDt"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="金融机构代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jrjgdm">
              <a-input v-model="model.jrjgdm" placeholder="请输入金融机构代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="内部机构号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nbjgh">
              <a-input v-model="model.nbjgh" placeholder="请输入内部机构号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="金融机构地区代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jrjgdqdm">
              <a-input v-model="model.jrjgdqdm" placeholder="请输入金融机构地区代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="借款人证件类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jkrzjlx">
              <a-input v-model="model.jkrzjlx" placeholder="请输入借款人证件类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="借款人证件代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jkrzjdm">
              <a-input v-model="model.jkrzjdm" placeholder="请输入借款人证件代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="借款人地区代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jkrdqdm">
              <a-input v-model="model.jkrdqdm" placeholder="请输入借款人地区代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="贷款借据编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dkjjbm">
              <a-input v-model="model.dkjjbm" placeholder="请输入贷款借据编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="贷款合同编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dkhtbm">
              <a-input v-model="model.dkhtbm" placeholder="请输入贷款合同编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="贷款产品类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dkcplb">
              <a-input v-model="model.dkcplb" placeholder="请输入贷款产品类别"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="贷款发放日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dkffrq">
              <j-date placeholder="请输入贷款发放日期" v-model="model.dkffrq"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="贷款到期日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dkdqrq">
              <j-date placeholder="请输入贷款到期日期" v-model="model.dkdqrq"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="贷款展期到期日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dkyqdqrq">
              <j-date placeholder="请输入贷款展期到期日期" v-model="model.dkyqdqrq"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="币种" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bz">
              <a-input v-model="model.bz" placeholder="请输入币种"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="贷款余额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dkye">
              <a-input-number v-model="model.dkye" placeholder="请输入贷款余额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="贷款余额折人民币" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dkyezrmb">
              <a-input-number v-model="model.dkyezrmb" placeholder="请输入贷款余额折人民币" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="利率是否固定" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="llsfgd">
              <a-input v-model="model.llsfgd" placeholder="请输入利率是否固定"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="利率水平" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="llsp">
              <a-input-number v-model="model.llsp" placeholder="请输入利率水平" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="贷款定价基准类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dkdjjzlx">
              <a-input v-model="model.dkdjjzlx" placeholder="请输入贷款定价基准类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="基准利率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jzll">
              <a-input-number v-model="model.jzll" placeholder="请输入基准利率" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="贷款财政扶持方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dkczfcfs">
              <a-input v-model="model.dkczfcfs" placeholder="请输入贷款财政扶持方式"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="贷款利率重新定价日" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dkllcxdjr">
              <j-date placeholder="请选择贷款利率重新定价日" v-model="model.dkllcxdjr"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="贷款担保方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dkdbfs">
              <a-input v-model="model.dkdbfs" placeholder="请输入贷款担保方式"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否首次贷款" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sfscdk">
              <a-input v-model="model.sfscdk" placeholder="请输入是否首次贷款"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="贷款质量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dkzl">
              <a-input v-model="model.dkzl" placeholder="请输入贷款质量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="贷款状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dkzt">
              <a-input v-model="model.dkzt" placeholder="请输入贷款状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="逾期类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yqlx">
              <a-input v-model="model.yqlx" placeholder="请输入逾期类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="贷款用途" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dkyt">
              <a-input v-model="model.dkyt" placeholder="请输入贷款用途"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="科目代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="subjectNo">
              <a-input v-model="model.subjectNo" placeholder="请输入科目代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="科目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="subjectName">
              <a-input v-model="model.subjectName" placeholder="请输入科目名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="客户名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="khmc">
              <a-input v-model="model.khmc" placeholder="请输入客户名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="客户代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="khdm">
              <a-input v-model="model.khdm" placeholder="请输入客户代码"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'JsPExPerLoansForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/jsPExPerLoans/jsPExPerLoans/add",
          edit: "/jsPExPerLoans/jsPExPerLoans/edit",
          queryById: "/jsPExPerLoans/jsPExPerLoans/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>
